package cn.lingnan.controller;

import lingnan.entity.Order;

import lingnan.service.OrderFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("order/consumer")
public class OrderControllerController {
    @Autowired
    private OrderFeignService orderFeignService;

    @GetMapping("toOrderList")
    public String toOrderList(Model model){
        System.out.println("consumer::::::::::::::::::::::::");
        List<Order> allOrder = orderFeignService.findAllOrder();
        System.out.println("consumer::::::::::::::::::::::::"+allOrder);
        model.addAttribute("orders",allOrder);
        return "order-list";
    }

    @DeleteMapping("/{id}")
    @ResponseBody
    public Boolean deleteById(@PathVariable("id") String id){
        System.out.println("consumer delete id is::::::::::"+id);
        return orderFeignService.deleteById(id);
    }

    @GetMapping("/")
    public String toAdd(Model model){
        model.addAttribute("order",new Order());
        return "order-add";
    }


    @PostMapping("save")
    @ResponseBody
    public  Order save(@RequestBody Order order){
        return orderFeignService.save(order);
    }




}
